package groupon.user.dao.impl;

import groupon.common.dao.impl.GenericDaoImpl;
import groupon.user.dao.AccountDao;
import groupon.user.model.Account;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

@Repository(value = "accountDao")
public class AccountDaoImpl extends GenericDaoImpl<Account, Long> implements AccountDao {

	final static Log logger = LogFactory.getLog(AccountDaoImpl.class);
	
	public Account findAccountByUsername(String username) {
		List<Account> listAccount = findAll(Account.class);
		for(Account act : listAccount){
			if(username.equals(act.getUsername())){
				return act;
			}
		}
		return null;
	}
	
	public void initializer() {
		Account account = new Account();
		account.setUsername("admin");
		account.setPassword("21232f297a57a5a743894a0e4a801fc3");
		account.setRole("BO");
		account.setEmail("hieu.ta@vn.pyramid-consulting.com");
		account.setActive(true);
		account.setCreatedBy("install");
		account.setCreatedDate(new Date());
		persist(account);
	}

	public Account findAccountbyEmail(String email) {
		List<Account> listAccount = findAll(Account.class);
		for(Account act : listAccount){
			if(email.equals(act.getEmail())){
				return act;
			}
		}
		return null;
	}
}